


#ifndef PF_DOCUMENT_H
#define PF_DOCUMENT_H

#include "pf_layerlist.h"
#include "pf_entitycontainer.h"
#include "pf_undo.h"
#include "lx_Export.h"

class PF_BlockList;

/**
 * Base class for documents. Documents can be either graphics or 
 * blocks and are typically shown in graphic views. Documents hold
 * an active pen for drawing in the Document, a file name and they
 * know whether they have been modified or not.
 *

 */
class LX_EXPORT PF_Document : public PF_Container,
    public PF_Undo {
public:
    PF_Document(PF_Container* parent=NULL);
    virtual ~PF_Document();

    virtual PF_LayerList* getLayerList() = 0;
    virtual PF_BlockList* getBlockList() = 0;

    virtual void newDoc() = 0;
    virtual bool save(bool isAutoSave = false) = 0;
    virtual bool saveAs(const QString &filename, LX_Define::FormatType type) = 0;
    virtual bool open(const QString &filename, LX_Define::FormatType type) = 0;
	

    /**
     * @return true for all document entities (e.g. Graphics or Blocks).
     */
    virtual bool isDocument() const {
        return true;
    }

    /**
     * Removes an entity from the entiy container. Implementation
     * from PF_Undo.
     */
    virtual void removeUndoable(PF_Undoable* u) {
        if (u!=NULL && u->undoRtti()==LX_Define::UndoableEntity) {
            removeEntity((PF_Entity*)u);
        }
    }

    /**
     * @return Currently active drawing pen.
     */
    PF_Pen getActivePen() const {
        return activePen;
    }

    /**
     * Sets the currently active drawing pen to p.
     */
    void setActivePen(PF_Pen p) {
        activePen = p;
    }

    /**
     * @return File name of the document currently loaded.
     * Note, that the default file name is empty.
     */
    QString getFilename() const {
        return filename;
    }
	
    /**
     * @return Auto-save file name of the document currently loaded.
     */
    QString getAutoSaveFilename() const {
        return autosaveFilename;
    }
	
    /**
     * Sets file name for the document currently loaded.
     */
    void setFilename(const QString& fn) {
        filename = fn;
    }

	/**
	 * Sets the documents modified status to 'm'.
	 */
	virtual void setModified(bool m) {
		//std::cout << "PF_Document::setModified: %d" << (int)m << std::endl;
		modified = m;
	}
	
	/**
	 * @retval true The document has been modified since it was last saved.
	 * @retval false The document has not been modified since it was last saved.
	 */
    virtual bool isModified() const {
        return modified;
    }
	
	/**
	 * Overwritten to set modified flag before starting an undo cycle.
	 */
    virtual void startUndoCycle() {
		setModified(true);
		PF_Undo::startUndoCycle();
	}


protected:
    /** Flag set if the document was modified and not yet saved. */
    bool modified;
    /** Active pen. */
    PF_Pen activePen;
    /** File name of the document or empty for a new document. */
    QString filename;
	/** Auto-save file name of document. */
        QString autosaveFilename;
	/** Format type */
	LX_Define::FormatType formatType;
};


#endif
